package auth

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetRoleInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取角色详情
func NewGetRoleInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleInfoLogic {
	return &GetRoleInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetRoleInfoLogic) GetRoleInfo(req *types.GetRoleInfoRequest) (resp *types.GetRoleInfoResponse, err error) {
	reply, err := l.svcCtx.AuthRoleRpc.GetRoleInfo(l.ctx, &v1.GetRoleInfoRequest{Id: req.Id})
	if err != nil {
		return nil, err
	}

	return &types.GetRoleInfoResponse{
		Id:          reply.GetId(),
		RolePid:     reply.GetRolePid(),
		RoleName:    reply.GetRoleName(),
		Description: reply.GetDescription(),
		Remark:      reply.GetRemark(),
		ListOrder:   reply.GetListOrder(),
		Status:      int8(reply.GetStatus()),
		CreatedAt:   reply.GetCreatedAt(),
		UpdatedAt:   reply.GetUpdatedAt(),
	}, err
}
